<?php
namespace app\index\model;
use GatewayClient\Gateway;
class Socket extends BaseModel{
    
    function bind($uid){
       $client_id = I('param.client_id');
       GateWay::bindUid($client_id, $uid);
       
       $data['data'] = Gateway::getAllClientCount();
      $data['type'] = "countChange";
       GateWay::sendToAll(json_encode($data));
       return $this->returnOk();
    }
    function bindAdmin($uid){
        $client_id = I('param.client_id');
        Gateway::joinGroup($client_id, "admin"); 
        $data['data'] = Gateway::getAllClientCount();
        $data['type'] = "countChange";
        GateWay::sendToAll(json_encode($data));
        return $this->returnOk();
    }
    function sendNew(){
        $data['type'] = 'refresh';
        GateWay::sendToAll(json_encode($data));
    }
    function sendResult($res,$name){
        $tmp['res'] = $res;
        $tmp['name'] = $name;
        $data['data'] = $tmp;
        $data['type'] = 'result';
        GateWay::sendToAll(json_encode($data));
    }
    function sendinfo($res,$user_id){
        $data['data'] = $res;
        $data['type'] = 'zhongjaing';
        GateWay::sendToUid($user_id,json_encode($data));
    }
    function sendinfo2($res,$user_id){
        $data['data'] = $res;
        $data['type'] = 'shule';
        GateWay::sendToUid($user_id,json_encode($data));
    }
    function sendadmin_moneychange(){
        $data['type'] = 'moneychange';
        Gateway::sendToGroup("admin", json_encode($data));
    }
    function send_admin_res($res){
       $data['type'] = 'kjinfo';
       $data['data'] = $res;
        Gateway::sendToGroup("admin", json_encode($data));
    }
    function sendAllInfo($res){
        $data['data'] = $res;
        $data['type'] = 'zjall';
        GateWay::sendToAll(json_encode($data));
    }
    function sendtest($res){
        $data['data'] = $res;
        $data['type'] = 'test';
        GateWay::sendToAll(json_encode($data));
    }
}
